/**
 * describe:
 *
 * @author chaP
 * @date 2019/01/10
 */
package CodingTest;

public class hasPathSum {
    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x){val = x;}
    }
    public boolean hasPathSum(TreeNode root ,int sum){
        if(root == null)
            return false;
        if(root.left == null && root.right == null)
            return sum - root.val == 0;
//        if(sum-root.val < 0)  return false;  这行代码一定要去掉 因为节点值可能为负数
        else return hasPathSum(root.left,sum - root.val) ||hasPathSum(root.right,sum-root.val);
    }
}
